

<template>

  <div>
     
     <div style="margin: 0.6rem;border-bottom: 1px #cfcfcf solid;" v-for="(item,index) in list">
       <div style="color:#7b7a7a;margin-top: 1.3rem;">{{item.comment}}</div>
       <div class="flex-row" style="">
         <div class="flex-row" style="width: 100%; margin-top: 0.6rem; justify-content: space-between; ">
           <div style=" padding-top: 0.3rem;">
             <div style="">{{item.title}}</div>
             <div style="color: #7b7a7a;font-size: 0.9rem">{{item.addtime_date}}</div>
           </div>
           <div @click="deleteMessage(index)" style="width:3.2rem;height: 1.6rem; color: white; background-color: #ff9612; margin: 0.8rem 0; padding: 0.15rem 0.5rem 0.05rem 0.5rem; box-sizing: border-box; border-radius: 0.3rem;font-size: 0.85rem">删除</div>
         </div>
       </div>
     </div>
     <!--<div style="width: 100%; height: 0.01rem; background-color: #e4e4e5; border-top:1px #cfcfcf solid;"></div>-->
     
     <toast v-model="showPositionValue" type="text" :time="800" is-show-mask :text="message" ></toast>
     
     <div v-if="list.length == 0" style="margin: 1rem auto; width: 50%; text-align: center; color:#7b7a7a ">暂无更多内容！</div>  
  </div>

</template>

<script>

import { Toast, Group, XSwitch, XButton ,base64} from 'vux'

export default {
  
  components: {
    Toast,
    Group,
    XSwitch,
    XButton,
    base64
  },

  data () {
    return {
      
      showPositionValue:false,
      list:'',
      id:'',
      message:'',
      access_token:''
    
    }
  },
  methods:{
     
    //获取详情
    getDetail(){
    	
	    	this.$store.commit('updateLoadingStatus',true);
	    	
	    	this.$http.get(this.$store.state.api + 'index/user-comment&access_token=' + this.access_token)
		    .then((response) => {
		    		
		    console.log(response)
				
				if(response.body.code == 0) {
					
					this.list = response.body.data
					
				} else {
					
				}
					
				
				this.$store.commit('updateLoadingStatus',false);	
				
			}, (response) => {
	             
	            
	            
			});
    
    },
    
    //删除留言
    deleteMessage(index){
    	
    	this.id = this.list[index].id
    	
    	console.log(this.id)
    	
    	this.$store.commit('updateLoadingStatus',true);
	    	
    	this.$http.get(this.$store.state.api + 'index/del-comment&access_token=' + this.access_token + '&id=' + this.id)
	    .then((response) => {
	    		
	    console.log(response)
			
			if(response.body.code == 0) {
				
				this.message = response.body.msg
				this.showPositionValue = true
				
				this.getDetail()
				
			} else {
				
			}
				
			
			this.$store.commit('updateLoadingStatus',false);	
			
		}, (response) => {
             
            
            
		});
    	
    	
    },
    
    //获取地址栏信息
		getUrlStr(name){
	      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
	      if(reg.test(window.location.href)){
	        return unescape(RegExp.$2.replace(/\+/g," "))
	      }
	      return undefined
	    },
    
  },
  
  mounted() {
  	
  	var access_token = this.getUrlStr('access_token');
           var parentId = this.getUrlStr('parent_id');
           
            if(parentId == undefined){
              parentId = 0;
           }
           
           var uid = this.getUrlStr('uid');
           
           if(parentId.toString().indexOf('?') > 0){
           	 parentId = parentId.split('?')[0];
           }
           
           var locurl = location.href;
           locurl = base64.encode(locurl.split('?')[0]);
           
       
           if(access_token != undefined){
         
              localStorage.setItem("access_token",access_token); 
              localStorage.setItem("parent_id",this.getUrlStr('uid'));


           }
           
            if(localStorage.getItem('access_token') != null){
         
              this.$root.registerjudge();
              this.$root.getShare();
              
            }else{
            	
        	  this.$root.gotoWechat(locurl,parentId);
            }
           
    	   this.access_token = localStorage.getItem('access_token');

    this.getDetail();

  },


}



</script>


<style lang="less" scoped>




</style>
